<template>
        <el-image v-if="url" :src="url"  v-bind="$attrs" v-on="$listeners"></el-image>
</template>

<script>
  import {listByIds} from '@/api/system/oss'
  export default {
    name: 'ossImage',
    props: {
      ossId:{
        type:Number|String,
        equired:true
      }
    },
    data(){
      return {
        url:null,
        loading:false
      }
    },
    created() {
      this.getUrl()
    },
    watch:{
      ossId(){
        this.getUrl()
      }
    },
    methods: {
      getUrl(){
        if(!this.loading && this.ossId){
          this.loading = true
          listByIds(this.ossId).then(res=>{
            res.data?.length>0 ? this.$set(this,'url',res.data[0].url)  : null
            this.$nextTick(()=>{
              this.loading = false
            })
          })
        }

      }
    },


  }
</script>

<style>
</style>
